<template>
  <div class="addMenus">
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="手机号">
        <el-input class="input" v-model="form.phone"></el-input>
      </el-form-item>
      <el-form-item label="昵称">
        <el-input class="input" v-model="form.nickname"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input class="input" v-model="form.password"></el-input> <el-button @click="clear" type="success">清空密码</el-button>
        <p>密码留空则不修改</p>
      </el-form-item>
      <el-switch
        class="mode"
        v-model="form.status"
        inactive-text="状态"
        :active-value="1"
        :inactive-value="2"
      >
      </el-switch>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">修改</el-button>
        <el-button type="info" @click="back">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import {  getMerberApi,setMerberApi } from "@/api/member";
export default {
  data() {
    return {
      password: '',  
      form: {
      },
    };
  },
  mounted() {
    this.getOne()
  },
  methods: {
    //获取一条数据
    async getOne(){
        let res=await getMerberApi(this.$route.query.uid)
        console.log(res.list[0]);
        this.form=res.list[0]
        this.password=res.list[0].password
        this.form.password=''
    },
    //返回
    back() {
      this.$router.push("/member");
    },
    //清空密码
    clear(){
        this.form.password=''
    },
    //提交
    async onSubmit() {
      if(this.form.password==''){
        this.form.password=this.password
      }
      let res = await setMerberApi(this.form);
      if (res.code == 200) {
        this.$message({
          type: "success",
          message: res.msg,
        });
      } else {
        this.$message({
          type: "warning",
          message: res.msg,
        });
      }
    },
  },
};
</script>
<style scoped lang="less">
.addMenus {
  .input {
    width: 40%;
  }
  .mode {
    margin: 0 0 30px 12px;
  }
}
/deep/ .avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
/deep/ .avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
/deep/ .avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>

